<template>
  <div>
    <el-card shadow>
      <el-form ref="form" :model="form" :rules="rules" label-width="120px">
        <el-row>
          <el-col :span="24">
            <el-form-item label="名称" prop="name">
              <el-input v-model="form.name" placeholder="" maxlength="30" />
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item label="备注">
              <el-input
                v-model="form.snote"
                :rows="5"
                maxlength="100"
                show-word-limit
                type="textarea"
                placeholder="请输入内容"
              ></el-input>
            </el-form-item>
          </el-col>

          <el-col :span="24">
            <el-form-item>
              <el-button type="primary" @click="submitForm">save</el-button>
            </el-form-item>
          </el-col>
        </el-row>
      </el-form>
    </el-card>
  </div>
</template>

<script>
import { archiveeService } from "@/api/sysService";
export default {
  dicts: [],
  components: {},
  props: {
    archiveeId: { type: String, default: "" },
    item: {
      type: Object,
      default: () => null,
    },
  },

  data() {
    return {
      resolve: null,

      // archiveeId: null,
      // 表单参数
      form: {
        id: undefined,
        name: undefined,
        archivee: {
          id: "",
        },
        snote: undefined,
      },

      // 表单校验
      rules: {
        name: [
          { required: true, message: "不能为空", trigger: "blur" },
          {
            min: 2,
            max: 20,
            message: "用户名称长度必须介于 2 和 20 之间",
            trigger: "blur",
          },
        ],
        price: [{ required: true, message: "不能为空", trigger: "blur" }],
      },
    };
  },
  // watch: {
  //   item(val) {
  //     val && (this.form = Object.assign({}, val));
  //   },
  // },

  created() {
    if (this.item) {
      this.form = Object.assign({}, this.item);
    }
  },
  methods: {
    /** 提交按钮 */
    submitForm: function () {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          this.form.archivee.id = this.archiveeId;
          archiveeService.postDocumentSave(this.form).then((response) => {
            this.$modal.msgSuccess("操作成功");
            this.$emit("refresh", this.form);
            // this.dialogVisible = false;
            // this.getList();
            // this.resolve(response.data);
          });
        }
      });
    },

    // 取消按钮
    cancel() {
      // this.dialogVisible = false;
      // this.reset();
    },
  },
};
</script>

<style lang="scss" scoped></style>
